/**
 * 
 */
package cs3201.westga.edu.project_2;

/**
 * This is the Cube class. A Cube can be described by its length.
 * @author Cody Stamps
 *
 */
public class Cube {
	
	private double length;
	
	
	/**
	 * Constructor for class Cube
	 * @param length
	 */
	public Cube(double _length) {
		setLength(_length);
	}
	
	/**
	 * getLength() - returns the current length of the Cube
	 * @return the length
	 */
	public double getLength() {
		return length;
	}
	
	/**
	 * setLength() sets the length of the Cube
	 * @param length - the length to set
	 * @throws IllegalArgumentException  if the length to be set is < 0
	 */
	public void setLength(double length) {
		//REQUIRES the Length be greater than 0
		//MODIFIES length
		//EFFECTS changes the length
		if (length <= 0 ){
			throw new IllegalArgumentException("Error: Invalid input. The length must be greater than 0.");
		}
		this.length = length;
	}
	
	
	
	/**
	 * hashCode() - generates a hashCode version of this Cube
	 * @return the hashCode version of this Cube
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(length);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	/**
	 * equals() - test if an object is equal to this Cube
	 * @return - true if object is equal, else false.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) //checks obj to this Cube
			return true; //if the same Cube return true.
		if (obj == null) //checks to make sure obj is not null
			return false; //if it is return false.
		if (getClass() != obj.getClass()) //checks to make sure obj's class is the same as this Cube
			return false; //if not return false.
		Cube other = (Cube) obj; //cast the obj as a Cube object.
		if (Double.doubleToLongBits(length) != Double // checks to see if other's base is the same as this Cube's length
				.doubleToLongBits(other.length)) 
			return false; //if it is not, return false
		return true; //else return true.
	}

	/**
	 * toString() - returns a string representation of this Cube.
	 * @return - the string representation of this Cube. 
	 */
	@Override
	public String toString() {
		return "Cube [length=" + length;
	}
	
	/**
	 * resize(double) - adjust the length according to the amount.
	 * @param amount - the size to readjust by.
	 */
	public void resize(double amount){
		//REQUIRES The amount > 0
		//MODIFIES length
		//EFFECTS The length will be multiplied by the amount.
		if (amount <= 0){
			throw new IllegalArgumentException("Error: The amount by which you want to resize is invalid.");
		}
		length = length * amount;
		System.out.println("The length is now: " + length); 
	}
	
	/**
	 * getVolume() - calculates the volume of this Cube.
	 * @return - the volume of this Cube
	 */
	public double getVolume(){
		return Math.pow(length, 3 );
	}

}
